import { h, render } from 'vue'
import CateSelectDialog from './CateSelectDialog.vue'

const selectCate = (storeId: number, selectCate: string): Promise<any> => {
  return new Promise((resolve) => {
    const model = true

    const vnode = h(CateSelectDialog, {
      modelValue: model,
      storeId,
      selectCate,
      onClose: () => {
        render(null, document.querySelector('#i-dialog')!)
      },
      onSelect: (val) => {
        resolve(val)
        render(null, document.querySelector('#i-dialog')!)
      }
    })
    render(vnode, document.querySelector('#i-dialog')!)
  })
}

export default selectCate
